package com.atyoung.youngmall.product.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author yangxiaoguang
 * @date 2020/5/30
 * 佛祖保佑             永无BUG
 */
public class ListValuesConstraintValidator implements ConstraintValidator<ListValues,Integer> {
    Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(ListValues constraintAnnotation) {
        int[] values = constraintAnnotation.values();
        for (Integer value : values){
            set.add(value);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
